<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('库存冻结')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">

                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">解冻人</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="jdry"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">冻结人</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="cjry"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">冻结单号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="djdh"/>
                        </div>
                    </div>

                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload">搜索</a>
                    </div>

                    <div class="moreSearch" style="display: none">

                        <div class="layui-inline">
                            <label class="layui-form-label">开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="stime" id="stime"
                                       placeholder="yyyy-MM-dd"/>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label"> </label>
                            <div class="layui-input-inline" style="height:20px">
                                --
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="etime" id="etime" placeholder="yyyy-MM-dd"/>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">解冻开始时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="start" id="start"
                                       placeholder="yyyy-MM-dd"/>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label"> </label>
                            <div class="layui-input-inline" style="height:20px">
                                --
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">解冻结束时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="end" id="end" placeholder="yyyy-MM-dd"/>
                            </div>
                        </div>
                    </div>
                </form>

                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <div class="group-button" id="toolbar">

                    <a class="layui-btn layui-btn-sm layui-btn-normal add-btn">
                         <i class="layui-icon">&#x1005;</i> 新增
                     </a>
                    <a class="layui-btn layui-btn-sm layui-btn-normal"id="out-put" >
                        <i class="layui-icon">&#x1005;</i> 导出
                    </a>
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<div th:include="/public/public_js::public_js"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script>
    $(function () {
        $(".moreBtn").on("click", function () {
            $(".moreSearch").toggle();
        });
        $(document).ready(function () {//通用方法去输入框前后空格
            $("form").on("change", function () {
                $("form input[type=text]").each(function () {
                    this.value = $.trim(this.value);
                });
            })
        });
    });
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        window.operateEvent = {
            "click #btn_qr": function (e, value, row, index) {//解冻库存
                editDialog(row.id);
            },
            /*"click #btn_bf": function (e, value, row, index) {//
                bf_Dialog(row.id);
            },*/
            "click #btn_dc": function (e, value, row, index) {//导出
                startDialog(row.id);
            }
        }

        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;

        //解冻库存
        function editDialog(id) {
            zzpUtils.dialog({
                title: "解冻库存",
                type: 2,
                content: "/Stock/Thawing?id=" + id,
                area: ['100%', '100%'], //设置dialog大小，也可以不设置，
                end: function () {//修改成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }

        $("#out-put").on("click",function(){
            var arr=[];
            var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length >0) {
                arr = $.map($rows, function (row) {
                    return row.id;
                })
            }
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:8080/zxsdwms/wmsstockfrozen/exportWmsStockFrozen", true);
            xhr.responseType = "blob";
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('Charset', 'utf-8');
            xhr.onload = function() {
                if (this.status == 200) {
                    var name = xhr.getResponseHeader("Content-disposition");
                    name=decodeURI(name);
                    var filename = name.substring(20,name.length);
                    var blob = new Blob([xhr.response], {type: 'text/xls'});
                    var csvUrl = URL.createObjectURL(blob);
                    var link = document.createElement('a');
                    link.href = csvUrl;
                    link.download = filename;
                    link.click();
                }
            };
            /*
            * 以下是将ids和对象拼接在一起
            * */
            var str=zzpUtils.getFormJson($("#searchForm"));
            var object2 = Object.assign({ids: arr}, str);
            /*将条件查询和ids传到后台*/
            xhr.send(JSON.stringify(
                object2
            ));
        })


            function startDialog(id) {
             var arr=[];
            /*var $rows = $table.bootstrapTable('getSelections');
            if ($rows.length >0) {
                arr = $.map($rows, function (row) {

                    return row.id;
                })
            }*/
                arr.push(id)
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:8080/zxsdwms/wmsstockfrozen/exportWmsStockFrozen", true);
            xhr.responseType = "blob";
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('Charset', 'utf-8');
            xhr.onload = function() {
                if (this.status == 200) {
                    var name = xhr.getResponseHeader("Content-disposition");
                    name=decodeURI(name);
                    var filename = name.substring(20,name.length);
                    var blob = new Blob([xhr.response], {type: 'text/xls'});
                    var csvUrl = URL.createObjectURL(blob);
                    var link = document.createElement('a');
                    link.href = csvUrl;
                    link.download = filename;
                    link.click();
                }
            };
            /*
            * 以下是将ids和对象拼接在一起
            * */
            var str=zzpUtils.getFormJson($("#searchForm"));
            var object2 = Object.assign({ids: arr}, str);
            /*将条件查询和ids传到后台*/
            xhr.send(JSON.stringify(
                object2
            ));
        }//导出结束

        /*顶部按钮多选启用*/
        $("#btn_qi").on('click', function () {
            var index = 0;
            var $rows = $table.bootstrapTable('getSelections');
            //判断选中的库区里是否有已经启用的
            for (var i = 0; i < $rows.length; i++) {
                if ($rows[i].jhzt == 1) {
                    index++;
                }
            }
        })
        //创建时间开始
        laydate.render({
            elem: '#stime'
            , theme: '#20a0ff',
        });
        //创建时间结束
        laydate.render({
            elem: '#etime'
            , theme: '#20a0ff',
        });
        //解冻开始时间
        laydate.render({
            elem: '#start'
            , theme: '#20a0ff'
        })
        //解冻结束时间
        laydate.render({
            elem: '#end'
            , theme: '#20a0ff'
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            url: '/wmsstockfrozen/list',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'djdh',
                title: '冻结单号'
            }, {
                field: 'cjsj',
                title: '创建时间'
            }, {
                field: 'jdsj',
                title: '解冻时间'
            }, {
                field: 'cjry',
                title: '冻结人'
            }, {
                field: 'jdry',
                title: '解冻人'
            }, {
                field: 'show_zt',
                title: '冻结状态'
            },{
                field: 'caozuo',
                title: '操作',
                events: operateEvent,
                formatter: operateFormatter
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            }
        });

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            if (row.zt == 0) {//冻结
                return [
                    '<a class="layui-btn layui-btn-xs" id="btn_qr">解冻</a>',
                    '<a class="layui-btn layui-btn-danger layui-btn-xs" id="btn_dc">导出</a>'
                ].join('')
            } else if(row.zt==1) {//部分冻结
                return [
                    '<a class="layui-btn layui-btn-xs" id="btn_qr">解冻</a>',
                    '<a class="layui-btn layui-btn-danger layui-btn-xs" id="btn_dc">导出</a>'
                ].join('')
            }else if(row.zt==2){//全部解冻（导出）
                return [
                    '<a class="layui-btn layui-btn-danger layui-btn-xs" id="btn_dc">导出</a>'
                ].join('')
            }
        }

        //查询
        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table");
        })

        /*新增库区*/
        $(".add-btn").on('click', function () {
            zzpUtils.dialog({
                title: "新增库存冻结",
                type: 2,
                content: "/Stock/Inventory",
                area: ['100%', '100%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        })

    });

</script>
</html>